package com.baweiwei.goodapi.controller;

import com.baweiwei.goodapi.service.GoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/good")
public class GoodController {

    @Autowired
    private GoodService goodService;

    @RequestMapping("/kuncun")
    public Map<String,Object> kuncun(Integer goodId,Integer num){
        Map<String,Object> map = new HashMap<>();
        int i = goodService.updateKunCun(goodId, num);
        if(i<=0){
            map.put("data",false);
            return map;
        }
        map.put("data",true);
        return map;
    }

    @RequestMapping("/gets")
    public List<Map> getGoods(){
        List<Map> list = new ArrayList<>();

        Map<String,Object> map =  new HashMap<String, Object>();
        map.put("name","小米2222");
        map.put("price",45.6);
        list.add(map);
        try {
            Thread.sleep(4000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return list;
    }
}
